package org.example.product.controller;

import org.example.core.utils.PageUtils;
import org.example.core.utils.R;
import org.example.product.entity.SpuInfoEntity;
import org.example.product.service.SpuInfoService;
import org.example.product.vo.SpuInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;




/**
 * @author 小杰_cc
 * @version 1.0
 */
@RestController
@RequestMapping("/pms/backend/spuInfo")
public class SpuInfoController {
    @Autowired
    private SpuInfoService spuInfoService;

    /**
     * 列表
     */
    @GetMapping("/list")
    public R<PageUtils> list(@RequestParam(required = false) String spuTitle,
                     @RequestParam(required = false) Long categoryId,
                     @RequestParam(required = false) Long brandId,
                     @RequestParam(required = false) Integer status,
                     @RequestParam(defaultValue = "1") Integer pageNum,
                     @RequestParam(defaultValue = "10") Integer pageSize){
        PageUtils pageUtils = spuInfoService.querySpuInfoList(spuTitle,categoryId, brandId, status, pageNum, pageSize);
        return R.ok(pageUtils);
    }

    /**
     * spu基本信息
     */
    @GetMapping("/info/{spuId}")
    public R<SpuInfoVo> info(@PathVariable("spuId") Long spuId){
        SpuInfoVo vo = spuInfoService.querySpuInfoById(spuId);
        return R.ok(vo);
    }

    /**
     * 修改spu基本信息
     */
    @PutMapping("/update")
    public R<?> update(@RequestBody SpuInfoEntity spuInfo){
        return spuInfoService.editSpuInfo(spuInfo)>0? R.ok():R.error();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    public R<?> delete(@RequestBody Long[] spuIds){

        return null;
    }

}
